// 古城发现
<template>
  <div
    class="page-container page-container-havePagination"
    :class="{ 'page-container-haveFooter': $store.state.settings.showFooter }"
  >
    <!-- 工具栏 -->
    <div class="head-search-container">
      <!-- 搜索 -->
      <el-form
        :inline="true"
        label-position="right"
        label-width="74px"
        size="small"
        :model="searchQuery"
        class="demo-form-inline"
      >
        <el-form-item label="古城名称">
          <el-input
            class="search-btn"
            size="small"
            :clearable="true"
            v-model="searchQuery.name"
            placeholder="输入名称搜索"
            @change="search()"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="success"
            class="greenColor"
            @click="search"
            >查询</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            class="greenColor"
            @click="addOldCity"
            >添加古城</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格渲染 -->
    <el-table
      header-row-class-name="table-header-style"
      :row-class-name="tableRowStyle"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      v-loading="loading"
    >
			<el-table-column
				prop="sort"
				label="序号"
				sortable
			>
			<template slot-scope="scope">
				<span>{{scope.row.sort?scope.row.sort:'暂无序号'}}</span>
			</template>
			</el-table-column>
      <el-table-column
        prop="name"
        label="古城名称"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column label="古城简介" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.oldCityProperty">{{
            scope.row.oldCityProperty.shortIntroduction
              ? scope.row.oldCityProperty.shortIntroduction
              : "暂无"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="现今国家" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.oldCityProperty">{{
            scope.row.oldCityProperty.currentCountry
              ? scope.row.oldCityProperty.currentCountry
              : "暂无"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所在区域" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.oldCityProperty">{{
            scope.row.oldCityProperty.locationRegion
              ? scope.row.oldCityProperty.locationRegion
              : "暂无"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所在大洲" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.oldCityProperty">{{
            scope.row.oldCityProperty.continent
              ? scope.row.oldCityProperty.continent
              : "暂无"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="语言/文化圈" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.oldCityProperty">{{
            scope.row.oldCityProperty.languageCulturalCircle
              ? scope.row.oldCityProperty.languageCulturalCircle
              : "暂无"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="240px">
        <template slot-scope="scope">
          <el-button type="primary" @click="changeSort(scope.row)"
            >编辑序号</el-button
          >
          <el-button type="success" @click="edit(scope.row, 'look')"
            >查看</el-button
          >
          <el-button @click="del(scope.row)">移除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <TablePagination
      :total="total"
      :currentPage="currentPage"
      :pageSize="pageSize"
      @changeSize="changeSize"
      @changePage="changePage"
      :class="[
        'table-pagination',
        { 'table-pagination-haveFooter': $store.state.settings.showFooter },
      ]"
    />
    <!-- 编辑弹窗 -->
    <editPopup ref="editPopup" :type="type" :item="editRow" @update="init" />
    <!-- 添加古城 -->
    <addCity ref="addCity" @update="init" />
		<!-- 编辑顺序 -->
		<sortPopup ref="sortPopup" @update="init" />
  </div>
</template>
<script>
import { MessageBox } from "element-ui";
import initData from "@/mixins/req";
import editPopup from "../oldCity/components/edit.vue";
import sortPopup from "./components/changeSort.vue";
import addCity from "./components/add.vue";
import { remove } from "@/api/oldCityFind/index.js";
export default {
  name: "findOldCity",
  mixins: [initData],
  components: {
    editPopup,
		sortPopup,
    addCity,
  },
  data() {
    return {
      searchQuery: {
        name: "", //名称
      },
      editRow: null,
      type: "edit",
    };
  },
  created() {
    this.init();
  },
  methods: {
    search() {
      this.currentPage = 1;
      this.init();
    },
    reloadSearch() {
      this.search();
    },
    beforeInit() {
      this.url = "/Recommend/list";
      this.cType = 2;
      this.searchParams = {
        current: this.currentPage,
        limit: this.pageSize,
        ...this.searchQuery,
      };
      return true;
    },
    edit(row, type) {
      this.editRow = row;
      this.type = type;
      this.$refs.editPopup.show = true;
    },
    async del(row) {
      MessageBox.confirm("您确定要从发现古城中移除该古城吗？", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        try {
          const req = remove({ oldCityId: row.id });
          const res = await req;
          this.init();
        } catch (error) {}
      });
    },
    // 添加古城
    addOldCity() {
      this.$refs.addCity.show = true;
    },
		// 编辑序号
		changeSort(row){
			this.$refs.sortPopup.show = true;
			this.$refs.sortPopup.form.oldCityId = row.id;
		}
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "~@/assets/styles/page.scss";
@import "~@/assets/styles/table.scss";
</style>

